package lium.lbs.lbsim.activity

import android.os.Bundle
import android.view.View
import com.buz.hjcdriver.bean.AResultBean
import com.buz.hjcdriver.bean.GetUserInfoResultBean
import lium.lbs.lbsim.utils.UserUtils
import com.lmlibrary.bean.ResponseBean
import lium.lbs.lbsim.utils.callbck.DialogCallback
import lium.lbs.lbsim.utils.callbck.JsonCallback
import lium.lbs.lbsim.utils.ToastUtils
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_changesignature.*
import lium.lbs.lbsim.R
import java.util.HashMap

class ChangeSignatureActivity: BaseActivity() {

    override fun getLayoutId(): Int { return R.layout.activity_changesignature  }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("签名")
        addOnClickListeners(R.id.btn_submit)
    }
    override fun getNetWorkData() {
    }

    override fun onResume() {
        super.onResume()
        getmyinfo()
    }
    override fun onClick(v: View?) {
        super.onClick(v)
        when(v!!.id){
            R.id.btn_submit -> {
                saveUserinfo()
            }
        }
    }

    private fun saveUserinfo() {
        val param = HashMap<String, String>()
        param["signature"] = tv_signature.text.toString()
        postData("/member/updMemberInfo",param, object : DialogCallback<ResponseBean<AResultBean>>(this) {
            override fun onSuccess(response: Response<ResponseBean<AResultBean>>) {
                ToastUtils.showToast(response.body().msg+"")
                finish()
            }
        })
    }

    private fun getmyinfo() {
        //隐示获取个人信息
        val param = HashMap<String, String>()
        postData("/member/getMemberInfo",param, object : JsonCallback<ResponseBean<GetUserInfoResultBean>>(this) {
            override fun onSuccess(response: Response<ResponseBean<GetUserInfoResultBean>>) {
                UserUtils.login(response.body().data.memberId+"")
                UserUtils.setUserData(
                    response.body().data.uniqueCode,
                    response.body().data.nickName,
                    response.body().data.headImage,
                    response.body().data.phone
                )
                tv_signature.setText(response.body().data.signature)
            }
        })
    }
}

